package avicit.bdp.oss.service.stats;

import avicit.bdp.oss.utils.upload.service.impl.OssUploadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-11-12 10:26
 * @类说明：BackgroundTaskService
 * @修改记录：
 * 功能：后台线程服务，定时获取bucket指标信息
 */
@Component
public class BackgroundTaskService {
    private static final Logger logger = LoggerFactory.getLogger(BackgroundTaskService.class);

    /**
     * bucket指标服务
     */
    @Autowired
    BucketAuditService bucketAuditService;

    @Autowired
    OssUploadService ossUploadService;


    @PostConstruct
    public void initialize() {
        logger.error("初始化后台合并线程...");
        new Thread(new Runnable() {
            @Override
            public void run() {
                ossUploadService.mergeTmpFile();
            }
        }).start();
    }

    /**
     * 定时任务，默认5min，获取bucket指标信息统计信息
     * 注意：DSS服务启动后，延迟60s执行此线程
     */
    @Scheduled(initialDelay= 60 * 1000, fixedDelayString = "60000")
    public void getBucketMetricTask() {
        logger.debug("开始执行查询桶指标定时任务...");

        this.bucketAuditService.runScheduledTask();

        logger.debug("查询桶指标定时任务执行完毕.");
    }
}
